<template>
  <div class="report-container">
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <!-- echarts指定的dom元素必须要有宽高 -->
      <div id="main" style="width: 600px; height: 400px"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import _ from 'lodash'
export default {
  name: 'Report',

  data() {
    return {
      // 需要被合并的数据
      option: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  // 在mounted生命周期函数中使用echarts，因为mounted生命周期中dom才渲染完毕
  async mounted() {
    const myChart = echarts.init(document.getElementById('main'))
    // 数据和配置项
    const { data: res } = await this.$http.get('reports/type/1')
    // 合并后的新对象作为echarts折线图选项
    myChart.setOption(_.merge(this.option, res.data))
  }
}
</script>

<style></style>
